package org.sang.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.sang.bean.Member;
import org.sang.mapper.provider.MemberProvider;

import java.util.List;

public interface MemberInfoMapper {
    @Insert("INSERT INTO t_member_info VALUES " +
                "(#{id}, #{name}, #{memberType}, #{idNum}, #{gender}," +
                " #{address}, #{age}, #{phoneNo}, #{cardNo}, #{storeId}," +
                " #{createdOperator},#{createdTime}," +
                " #{updateOperator},#{updateTime})")
    int save(Member member);

    //修改
    @Update("UPDATE t_member_info " +
                "SET name=#{member.name}," +
                "member_type=#{member.memberType}," +
                "id_number=#{member.idNum}," +
                "gender=#{member.gender}," +
                "address=#{member.address}," +
                "age=#{member.age}," +
                "phone_no=#{member.phoneNo}," +
                "card_no=#{member.cardNo}," +
                "store_id=#{member.storeId}," +
                "update_operator=#{member.updateOperator}," +
                "update_time=#{member.updateTime} " +
                "WHERE id=#{memberId}")
    int update(@Param("member")Member member,@Param("memberId")String memberId);

    @Delete("DELETE FROM t_member_info WHERE id=#{memberId}")
    int delete(String memberId);

    @SelectProvider(type = MemberProvider.class, method = "queryMemberParam")
    @ResultMap("org.sang.mapper.MemberInfoMapper.BaseResultMap")
    List<Member> getMemberByPage(Member member);

    @Select("SELECT * FROM t_member_info WHERE id = #{id}")
    @ResultMap("org.sang.mapper.MemberInfoMapper.BaseResultMap")
    Member getMemberById(String id);

    @Select("SELECT count(*) FROM t_member_info WHERE card_no = #{cardNo} AND store_id= #{storeId} ")
    int getCountMemberByCardAndStore(@Param("cardNo")String cardNo, @Param("storeId")String storeId);

    @Select("SELECT count(*) FROM t_member_info WHERE id_number = #{idNum}")
    int getCountMemberByIdNum(String idNum);

}
